<template>
  <view class="ranking-item">
    <view class="rank">
      <template v-if="rank <= 3">
        <view class="medal" :class="medalClass">
          <text class="icon">{{ medalIcon }}</text>
        </view>
      </template>
      <template v-else>
        <text class="rank-text">{{ rank }}</text>
      </template>
    </view>
    
    <view class="user-info">
      <text class="username">{{ user.username }}</text>
      <text class="score">{{ user.score }} 积分</text>
    </view>
    
    <view class="user-score">
      <text class="score">{{ user.score }}</text>
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  rank: {
    type: Number,
    required: true
  },
  user: {
    type: Object,
    required: true,
    default: () => ({ username: '', score: 0 })
  }
})

const medalClass = computed(() => {
  switch (props.rank) {
    case 1: return 'gold';
    case 2: return 'silver';
    case 3: return 'bronze';
    default: return '';
  }
})

const medalIcon = computed(() => {
  switch (props.rank) {
    case 1: return '🏆';
    case 2: return '🥈';
    case 3: return '🥉';
    default: return '';
  }
})
</script>

<style scoped>
.ranking-item {
  display: flex;
  align-items: center;
  padding: 16rpx;
  border-radius: 8rpx;
  background-color: rgba(30, 30, 50, 0.5);
  margin-bottom: 12rpx;
}

.rank {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16rpx;
}

.medal {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32rpx;
}

.medal.gold {
  background: linear-gradient(to bottom, #FFD700, #FFA500);
}

.medal.silver {
  background: linear-gradient(to bottom, #C0C0C0, #A9A9A9);
}

.medal.bronze {
  background: linear-gradient(to bottom, #CD7F32, #D2691E);
}

.rank-text {
  font-size: 28rpx;
  font-weight: bold;
  color: #ccc;
  width: 40rpx;
  height: 40rpx;
  background-color: #333;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-info {
  flex: 1;
}

.username {
  font-size: 30rpx;
  color: #fff;
  display: block;
  margin-bottom: 4rpx;
}

.score {
  font-size: 24rpx;
  color: #888;
}

.user-score {
  font-size: 32rpx;
  font-weight: bold;
  color: #FFD700;
}
</style>